\subsection{Linear algebra}

The $dot$ function is used to multiply tensors.
For example, let
\begin{equation*}
A=\begin{pmatrix}1&2\\3&4\end{pmatrix}
\quad{\rm and}\quad x=\begin{pmatrix}x_1\\x_2\end{pmatrix}
\end{equation*}

\noindent
The product $Ax$ is computed as follows.

{\color{blue}
\begin{verbatim}
A = ((1,2),(3,4))
x = (x1,x2)
dot(A,x)
\end{verbatim}
}

\noindent
$\begin{bmatrix}
x_1+2x_2\\
3x_1+4x_2
\end{bmatrix}$

\bigskip
\noindent
The following example shows how to use $dot$ and $inv$ to solve for
the vector $X$ in $AX=B$.

{\color{blue}
\begin{verbatim}
A = ((3,7),(1,-9))
B = (16,-22)
X = dot(inv(A),B)
X
\end{verbatim}
}

\noindent
$X=\begin{bmatrix}-\tfrac{5}{17}\\ \\ \tfrac{41}{17}\end{bmatrix}$

\bigskip
\noindent
The $dot$ function can have more than two arguments.
For example, $dot(A,B,C)$ can be used for the dot product of three tensors.

\bigskip
\noindent
Square brackets are used for component access.
Index numbering starts with 1.

{\color{blue}
\begin{verbatim}
A = ((a,b),(c,d))
A[1,2] = -A[1,1]
A
\end{verbatim}
}

\noindent
$\begin{bmatrix}a&-a\\c&d\end{bmatrix}$

\bigskip
\noindent
The following example demonstrates the relation
$A^{-1}=\frac{\operatorname{adj}A}{\operatorname{det}A}$.

{\color{blue}
\begin{verbatim}
A = ((a,b),(c,d))
inv(A)
\end{verbatim}
}

\noindent
$\begin{bmatrix}\frac{d}{ad-bc} & -\frac{b}{ad-bc}\\-\frac{c}{ad-bc} & \frac{a}{ad-bc}\end{bmatrix}$

{\color{blue}
\begin{verbatim}
adj(A)
\end{verbatim}
}

\noindent
$\begin{bmatrix}d & -b\\-c & a\end{bmatrix}$

{\color{blue}
\begin{verbatim}
det(A)
\end{verbatim}
}

\noindent
$ad-bc$

{\color{blue}
\begin{verbatim}
inv(A) - adj(A)/det(A)
\end{verbatim}
}

\noindent
$\begin{bmatrix}0 & 0\\0 & 0\end{bmatrix}$

\bigskip
\noindent
Sometimes a calculation will be simpler if it can be reorganized to use
$adj$ instead of $inv$.
The main idea is to try to prevent the determinant from appearing as a
divisor.
For example, suppose for matrices $A$ and $B$ you want to check that
\begin{equation*}
{A}-{B}^{-1}=0
\end{equation*}
Depending on the complexity of $\mathop{\rm det}B$, the software
may not be able to find a simplification that yields zero.
Should that occur, the following alternative formulation can be tried.
\begin{equation*}
A\operatorname{det}B-\operatorname{adj}B=0
\end{equation*}
